package com.xiaoshuidi.cloud.module.member.mapper.securitycheck;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.framework.mybatis.core.mapper.BaseMapperX;
import com.xiaoshuidi.cloud.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.xiaoshuidi.cloud.module.member.pojo.securitycheck.SecurityCheckDO;
import org.apache.ibatis.annotations.Mapper;
import com.xiaoshuidi.cloud.module.member.controller.admin.securitycheck.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 安全检查 Mapper
 *
 * @author hans.zhang
 */
@Mapper
public interface SecurityCheckMapper extends BaseMapperX<SecurityCheckDO> {

    default PageResult<SecurityCheckDO> selectPage(SecurityCheckPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SecurityCheckDO>()
                .orderByDesc(SecurityCheckDO::getId));
    }

    default List<SecurityCheckDO> selectList(SecurityCheckExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<SecurityCheckDO>()
                .eqIfPresent(SecurityCheckDO::getSecurityCheckProgramId, reqVO.getSecurityCheckProgramId())
                .eqIfPresent(SecurityCheckDO::getInspectorate, reqVO.getInspectorate())
                .eqIfPresent(SecurityCheckDO::getSecurityCheckType, reqVO.getSecurityCheckType())
                .eqIfPresent(SecurityCheckDO::getPitfallLevel, reqVO.getPitfallLevel())
                .betweenIfPresent(SecurityCheckDO::getCheckDate, reqVO.getCheckDate())
                .eqIfPresent(SecurityCheckDO::getIsNeedRectification, reqVO.getIsNeedRectification())
                .eqIfPresent(SecurityCheckDO::getCheckPhoto, reqVO.getCheckPhoto())
                .eqIfPresent(SecurityCheckDO::getIsPlaceOnFile, reqVO.getIsPlaceOnFile())
                .betweenIfPresent(SecurityCheckDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SecurityCheckDO::getCreateTime));
    }

    @Select("SELECT " +
            "msc.id as id, " +
            "mscp.check_work_unit as checkWorkUnit, " +
            "mscp.NAME as name, " +
            "msc.security_check_type as securityCheckType, " +
            "msc.check_date as checkDate, " +
            "msc.inspectorate as inspectorate, " +
            "msc.pitfall_level as pitfallLevel, " +
            "msc.is_need_rectification as isNeedRectification, " +
            "msc.is_place_on_file as isPlaceOnFile, " +
            "msc.creator as creator, " +
            "msc.wilfulness as wilfulness, " +
            "msc.timeframe as timeframe " +
            "FROM " +
            "member_security_check msc, " +
            "member_security_check_program mscp  " +
            "WHERE " +
            "msc.security_check_program_id = mscp.id and msc.deleted = false and mscp.deleted = 0 and ${ew.sqlSegment} ")
    Page<SecurityCheckRespVO> page(Page<Object> objectPage,@Param("ew") QueryWrapper<SecurityCheckDO> wrapper);
}
